<?php

/**
 * sector actions.
 *
 * @package    espazio
 * @subpackage sector
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class sectorActions extends sfActions
{
  public function executeIndiceGeneral(sfWebRequest $request)
  {
   // EMPRESA
   // En el indice general mostraremos todos los sectores ordenados alfabeticamente
     $c = new Criteria();
     $c->addAscendingOrderByColumn(SectorPeer::SECTOR);
     $this->sector_list = SectorPeer::doSelect($c);

   // FORMACION
   // En el indice general mostraremos las familias de estudios de PRIMER NIVEL
     $criteria = new Criteria();
     $criteria -> add(FamiliaPeer::PADRE,1);
     //$c->addAscendingOrderByColumn(FamiliaPeer::ID);
     $this->formacion_primer_nivel_list = FamiliaPeer::doSelect($criteria);
  }

  public function executeIndex(sfWebRequest $request)
  {
    $this->sector_list = SectorPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->sector = SectorPeer::retrieveByPk($request->getParameter('id'));
    $this->forward404Unless($this->sector);
    
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new SectorForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new SectorForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($sector = SectorPeer::retrieveByPk($request->getParameter('id')), sprintf('Object sector does not exist (%s).', $request->getParameter('id')));
    $this->form = new SectorForm($sector);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($sector = SectorPeer::retrieveByPk($request->getParameter('id')), sprintf('Object sector does not exist (%s).', $request->getParameter('id')));
    $this->form = new SectorForm($sector);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($sector = SectorPeer::retrieveByPk($request->getParameter('id')), sprintf('Object sector does not exist (%s).', $request->getParameter('id')));
    $sector->delete();

    $this->redirect('sector/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $sector = $form->save();

      $this->redirect('sector/edit?id='.$sector->getId());
    }
  }
/*
  public function dameHijosFamilia($padre){
   // FORMACION
   // En el indice general mostraremos las familias de estudios de PRIMER NIVEL
        $criteria = new Criteria();
        $criteria -> add(FamiliaPeer::PADRE,$familia->getID());
        //$c->addAscendingOrderByColumn(FamiliaPeer::ID);
        $this->formacion_list = FamiliaPeer::doSelect($criteria);
        //var_dump($formacion_list);
  }
 *
 */
}
